package com.cloudcc.mobile.dao.impl;

import java.net.URLEncoder;

import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.dao.HandleDao;
import com.cloudcc.mobile.util.NetWork;
import com.cloudcc.mobile.util.Tools;
import com.cloudcc.mobile.util.UrlTools;

public class HandleDaoImpl implements HandleDao {
	/** * 喜欢 praiseFeed */
	public String xihuan(String praiseFeed) {
		String json = "";
		try {
			String data = URLEncoder.encode(praiseFeed, "utf-8");
			String url = UrlTools.url + UrlTools.url_path
					+ "serviceName=praiseFeed&data=" + data + "&binding="
					+ AppContext.binding;
			json = NetWork.get(url);
		} catch (Exception e) {
			Tools.handle(e);
		}
		return json;
	}

	/** * 收藏 favourite favoriteFeed */
	@Override
	public String shoucang(String favoriteFeed) {
		try {
			String data = URLEncoder.encode(favoriteFeed, "utf-8");
			String url = UrlTools.url + UrlTools.url_path
					+ "serviceName=favoriteFeed&data=" + data + "&binding="
					+ AppContext.binding;
			String json = NetWork.get(url);
			return json;
		} catch (Exception e) {
			Tools.handle(e);
		}
		return null;
	}

	/** * 留言 */
	@Override
	public String liuyan() {
		return null;
	}

	@Override
	public String removetiezi(String removeMicroPost) {
		try {
			String data = URLEncoder.encode(removeMicroPost, "utf-8");
			String url = UrlTools.url + UrlTools.url_path
					+ "serviceName=removeMicroPost&data=" + data + "&binding="
					+ AppContext.binding;
			Tools.i("login", "removetiezi---url---" + url);
			String json = NetWork.get(url);
			Tools.i("login", "removetiezi---result---" + json);
			return json;
		} catch (Exception e) {
			Tools.handle(e);
		}
		return null;
	}

	/**
	 * 删除评论
	 */
	@Override
	public String removecomment(String data) {
		try {
			String Data = URLEncoder.encode(data, "utf-8");
			String url = UrlTools.url + UrlTools.url_path
					+ "serviceName=removeMicroComment&data=" + Data
					+ "&binding=" + AppContext.binding;
			String json = NetWork.get(url);
			return json;
		} catch (Exception e) {
			Tools.handle(e);
		}
		return null;
	}

	/**
	 * 喜欢或取消喜欢评论
	 */
	@Override
	public String praisedcomment(String data) {
		try {
			String Data = URLEncoder.encode(data, "utf-8");
			String url = UrlTools.url + UrlTools.url_path
					+ "serviceName=praiseComment&data=" + Data + "&binding="
					+ AppContext.binding;
			String json = NetWork.get(url);
			return json;
		} catch (Exception e) {
			Tools.handle(e);
		}
		return null;
	}

	@Override
	public String insertLead(String data) {
		String json = "";
		try {
			String Data = URLEncoder.encode(data, "utf-8");
			String url = UrlTools.url
					+ UrlTools.url_path
					+ "serviceName=insertWithRoleRight&objectApiName=Lead&data=["
					+ Data + "]&binding=" + AppContext.binding;
			json = NetWork.get(url);
		} catch (Exception e) {
			Tools.handle(e);
		}
		return json;
	}

	@Override
	public String insertAccount(String data) {
		String json = "";
		try {
			String Data = URLEncoder.encode(data, "utf-8");
			String url = UrlTools.url
					+ UrlTools.url_path
					+ "serviceName=insertWithRoleRight&objectApiName=Account&data=["
					+ Data + "]&binding=" + AppContext.binding;
			json = NetWork.get(url);
		} catch (Exception e) {
			Tools.handle(e);
		}
		return json;
	}

	@Override
	public String insertContact(String data) {
		String json = "";
		try {
			String Data = URLEncoder.encode(data, "utf-8");
			String url = UrlTools.url
					+ UrlTools.url_path
					+ "serviceName=insertWithRoleRight&objectApiName=Contact&data=["
					+ Data + "]&binding=" + AppContext.binding;
			json = NetWork.get(url);
		} catch (Exception e) {
			Tools.handle(e);
		}
		return json;
	}

	@Override
	public String getAccount(int pageNUM, int pageSize, String expressions) {
		String jsonString = null;
		try {
			String encode = URLEncoder.encode(expressions, "utf-8");
			String url = UrlTools.url
					+ UrlTools.url_path
					+ "serviceName=pageQueryWithRoleRight&objectApiName=Account&expressions="
					+ encode + "&binding=" + AppContext.binding + "&pageNUM="
					+ pageNUM + "&pageSize=" + pageSize;
			jsonString = NetWork.get(url);
			return jsonString;
		} catch (Exception e) {
			Tools.handle(e);
		}
		return jsonString;
	}

}
